﻿using System.Diagnostics;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.SpecializedProperties;
using PageTypeBuilder;
using TemplateFoundation.CustomProperties;
using TemplateFoundation.Tabs;
using TemplateFoundation.Tags;

namespace TemplateFoundation.PageTypes
{
    /// <summary>
    /// The base class for all page types in an EPiServer Template Foundation project
    /// </summary>
    [DebuggerDisplay("[{PageTypeName}] {PageName}")]
    public abstract class PageTypeBase : TypedPageData, IPageType
    {
        #region Page properties

        /// <summary>
        /// Gets or sets the tags for the page
        /// </summary>
        /// <remarks>Sort order: 100</remarks>
        [PageTypeProperty(
            EditCaption = "Tags",
            HelpText = "Add tags to this page to categorize its contents",
            UniqueValuePerLanguage = true,
            SortOrder = 100,
            Type = typeof (PropertyTags),
            Tab = typeof (RelatedTab))]
        public virtual TagCollection Tags { get; set; }
        
        /// <summary>
        /// Gets or sets the page title if different from the page name
        /// </summary>
        /// <remarks>Sort order: 200</remarks>
        [PageTypeProperty(
            EditCaption = "Page title",
            HelpText = "The title to use for the page if different from the page name",
            UniqueValuePerLanguage = true,
            SortOrder = 200,
            Type = typeof (PropertyString),
            Tab = typeof (SeoTab))]
        public virtual string Title { get; set; }

        /// <summary>
        /// Gets or sets the pages description, defaults to part of main body for editorial pages
        /// </summary>
        /// <remarks>Sort order: 300</remarks>
        [PageTypeProperty(
            EditCaption = "Description",
            HelpText = "Description of the page's contents",
            UniqueValuePerLanguage = true,
            SortOrder = 300,
            Type = typeof (PropertyLongString),
            Tab = typeof (SeoTab))]
        public virtual string Description { get; set; }

        /// <summary>
        /// Gets or sets a comma-separated list of keywords for the page
        /// </summary>
        /// <remarks>Sort order: 400</remarks>
        [PageTypeProperty(
            EditCaption = "Keywords",
            HelpText = "Comma-separated list of keywords",
            UniqueValuePerLanguage = true,
            SortOrder = 400,
            Type = typeof (PropertyString),
            Tab = typeof (SeoTab))]
        public virtual string Keywords { get; set; }

        /// <summary>
        /// Gets or sets the author of the page
        /// </summary>
        /// <remarks>Used for the author meta tag. Sort order = 500.</remarks>
        [PageTypeProperty(
            EditCaption = "Author",
            HelpText = "Name of the author of the page",
            UniqueValuePerLanguage = false,
            SortOrder = 500,
            Type = typeof (PropertyString),
            Tab = typeof (SeoTab))]
        public virtual string Author { get; set; }

        /// <summary>
        /// Gets or sets the copyright information for the page
        /// </summary>
        /// <remarks>Used for the copyright meta tag. Sort order = 600.</remarks>
        [PageTypeProperty(
            EditCaption = "Copyright",
            HelpText = "Copyright information for the page",
            UniqueValuePerLanguage = false,
            SortOrder = 600,
            Type = typeof (PropertyString),
            Tab = typeof (SeoTab))]
        public virtual string Copyright { get; set; }

        /// <summary>
        /// Gets or sets whether search engines are allowed to index the page
        /// </summary>
        /// <remarks>Sort order: 700</remarks>
        [PageTypeProperty(
            EditCaption = "Allow indexing",
            HelpText = "Controls if the page should be indexed by search engines",
            UniqueValuePerLanguage = false,
            DefaultValue = "true",
            DefaultValueType = DefaultValueType.Value,
            SortOrder = 700,
            Type = typeof (PropertyBoolean),
            Tab = typeof (SeoTab))]
        public virtual bool EnableIndexing { get; set; }

        /// <summary>
        /// Gets or sets whether search engines are allowed to follow links on the page
        /// </summary>
        /// <remarks>Sort order: 800</remarks>
        [PageTypeProperty(
            EditCaption = "Allow link following",
            HelpText = "Controls if search engines should follow links on the page",
            UniqueValuePerLanguage = false,
            DefaultValue = "true",
            DefaultValueType = DefaultValueType.Value,
            SortOrder = 800,
            Type = typeof (PropertyBoolean),
            Tab = typeof (SeoTab))]
        public virtual bool EnableLinkFollowing { get; set; }

        /// <summary>
        /// Gets or sets related links for the page
        /// </summary>
        /// <remarks>Sort order: 200</remarks>
        [PageTypeProperty(
            EditCaption = "Related links",
            HelpText = "Links to relevant pages and documents",
            DisplayInEditMode = true,
            UniqueValuePerLanguage = true,
            SortOrder = 200,
            Tab = typeof (RelatedTab),
            Type = typeof (PropertyLinkCollection),
            Searchable = false)]
        public virtual LinkItemCollection RelatedLinks { get; set; }

        /// <summary>
        /// Gets or sets the contact person for the page
        /// </summary>
        /// <remarks>Sort order: 100</remarks>
        [PageTypeProperty(
            EditCaption = "Page contact",
            HelpText = "Contact for this page",
            DisplayInEditMode = true,
            UniqueValuePerLanguage = false,
            SortOrder = 100,
            Tab = typeof (RelatedTab),
            Type = typeof (PropertyContact),
            Searchable = false)]
        public virtual PageReference PageContact { get; set; }

        #endregion
    }
}